package middleware

import (
	"fmt"
	"jingdong-product/api/internal/types"
	"jingdong-product/pkg"
	"net/http"
)

type UserAgentMiddleware struct {
}

func NewUserAgentMiddleware() *UserAgentMiddleware {
	return &UserAgentMiddleware{}
}

func (m *UserAgentMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		// TODO generate middleware implement function, delete after code implementation
		//token:=

		GetToken, m := pkg.GetToken("token")
		if m != "" {
			reps := types.Response{
				Message: "过期",
				Data:    GetToken,
				Code:    500,
			}
			fmt.Println(reps)
			//httpx.OkJsonCtx()
			return
		}

		r.ParseForm()
		r.Form.Get("token")
		// Passthrough to next handler if need
		next(w, r)
	}
}
